<?php

namespace common\models;

use Yii;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "{{%chat}}".
 *
 * @property integer $id
 * @property string $content
 * @property string $userId
 * @property string $username
 * @property string $parent_id
 * @property integer $status
 * @property integer $weight
 * @property string $created_at
 * @property string $updated_at
 * @property string $res1
 * @property string $res2
 * @property string $res3
 */
class Chat extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%chat}}';
    }

    public function behaviors()
    {
        return [
            TimestampBehavior::className(),
        ];
    }
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['userId', 'content','username'], 'required'],
            [[ 'parent_id','to', 'status', 'weight'], 'integer'],
            [['content'], 'string', 'max' => 500],
            [['userId','username'], 'string', 'max' => 40],
            [['res1', 'res2', 'res3'], 'string', 'max' => 80]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'content' => 'Content',
            'userId' => 'User ID',
            'username' => 'Username',
            'parent_id' => 'Parent ID',
            'status' => 'Status',
            'weight' => 'Weight',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
            'res1' => 'Res1',
            'res2' => 'Res2',
            'res3' => 'Res3',
        ];
    }
    public function getRelationUserMess()
    {
        return $this->hasOne(UserMess::className(), ['uid' => 'userId']);
    }
    public function getRelationImg()
    {
        return $this->hasOne(Img::className(), ['uid' => 'userId']);
    }
}
